package com.tnr.scgcxx.service.process.impl;

import com.tnr.scgcxx.dao.process.RawclothDao;
import com.tnr.scgcxx.model.bus.Plan;
import com.tnr.scgcxx.model.bus.Process;
import com.tnr.scgcxx.service.process.RawclothService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class RawclothServiceImpl implements RawclothService {
    @Autowired
    private RawclothDao rawclothDao;


    @Override
    public List<Process> findProcesss(Process process) {
        return rawclothDao.findProcesss(process);
    }

    @Override
    public List<Plan> findPlans() {
        return rawclothDao.findPlans();
    }

    @Override
    public Plan findPlanById(Integer plan_id) {
        return rawclothDao.findPlanById(plan_id);
    }

    @Override
    public int addRawcloth(Plan plan, Process process) {

        Process process1 = new Process();
        process1.setPlan_id(plan.getPlan_id());
        process1.setProcess_cus(plan.getCus_id()+"|"+plan.getCus_name());
        process1.setProcess_color(plan.getCo_id()+"|"+plan.getCo_name());
        process1.setProcess_std(plan.getStandard_id()+"|"+plan.getStandard_name());
        process1.setGroup_num(process.getGroup_num());
        process1.setGroup_date(process.getGroup_date());
        process1.setGroup_person(process.getGroup_person());

        return  rawclothDao.addRawcloth(process1);
    }

    @Override
    public int deleteRawclothByIds(Long[] process_ids) {
        return rawclothDao.deleteRawclothByIds(process_ids);
    }

    @Override
    public int updateRawclothStatusByIds(Long[] process_ids, String process_status) {
        return rawclothDao.updateRawclothStatusByIds(process_ids,process_status);
    }

    @Override
    public int deleteRawclothById(Long process_id) {
        return rawclothDao.deleteRawclothById(process_id);
    }

    @Override
    public int updateRawcloth(Plan plan) {
        Plan plan1 =  new Plan();
        plan1.setProcess_id(plan.getProcess_id());
        plan1.setGroup_num(plan.getGroup_num());
        plan1.setGroup_date(plan.getGroup_date());
        plan1.setGroup_person(plan.getGroup_person());
        plan1.setProcess_status(plan.getProcess_status());
        return rawclothDao.updateRawcloth(plan1);
    }

    @Override
    public Plan findRawclothById(Long process_id) {
        Plan plan=  rawclothDao.findRawclothById(process_id);
        BigDecimal plan_residue = plan.getPlan_residue();
        BigDecimal group_num = plan.getGroup_num();
        plan.setPlan_residue(plan_residue.add(group_num));
        return plan;
    }
}
